﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HF.Framework.SqlDataContract;
using System.Data;
using HF.Framework.DataClientDBAgent;

namespace HF.Business.OA
{
    public class OA_Cost
    {
        private SqlDataItem sqlDataItem = new SqlDataItem();
        private SqlDataItem sqlDataItem1 = new SqlDataItem();
        public string ID = "";
        public string Code = "";
        public string Name = "";
        public string typeName = "";
        public int Resmoney = 0;
        public string Lendmoney = "";
        public int Userlendmoney = 0;

        public string WorkflowId = "";
        public string WorkflowInsId = "";
        public string WorktaskId = "";
        public string WorktaskInsId = "";



        /// <summary>
        /// 获得OA_Cost表数据
        /// </summary>
        /// <param name=WorkflowInsId></param>
        /// <returns></returns>
        public static DataTable GetOA_CostTable(string workflowInsId)
        {
            try
            {
                string sql = "select * from OA_Cost where WorkflowInsId=@workflowInsId";
                SqlDataItem sqlItem = new SqlDataItem();
                sqlItem.CommandText = sql;
                sqlItem.AppendParameter("@workflowInsId", workflowInsId);
                ClientDBAgent agent = new ClientDBAgent();
                return agent.ExecuteDataTable(sqlItem);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        public void GetOA_CostInfo(string workflowinsid)
        {
            DataTable dt = GetOA_CostTable(workflowinsid);
            if (dt != null && dt.Rows.Count > 0)
            {
                ID = dt.Rows[0]["ID"].ToString();
                Code = dt.Rows[0]["Code"].ToString();
                Name = dt.Rows[0]["Name"].ToString();
                typeName = dt.Rows[0]["typeName"].ToString();
                Resmoney = Convert.ToInt32(dt.Rows[0]["Resmoney"]);
                Lendmoney = dt.Rows[0]["Lendmoney"].ToString();
                Userlendmoney = Convert.ToInt32(dt.Rows[0]["Userlendmoney"]);
                WorkflowId = dt.Rows[0]["WorkflowId"].ToString();
                WorkflowInsId = dt.Rows[0]["WorkflowInsId"].ToString();
                WorktaskId = dt.Rows[0]["WorktaskId"].ToString();
            }
        }

        /// <summary>
        /// 增加fin_Evection
        /// </summary>
        public void Insert(OA_Cost oacost)
        {
            try
            {
                string sql = "delete OA_Cost where WorkflowinsId=@WorkflowInsId";//先删除原有数据
                sqlDataItem.CommandText = sql;
                sqlDataItem.AppendParameter("@WorkflowInsId", WorkflowInsId);
                sql = "insert OA_Cost(ID,Code,Name,typeName,Resmoney,Lendmoney,Userlendmoney," +
                "Workflowid,Worktaskid,Workflowinsid,Worktaskinsid)" +
                " values(@ID,@Code,@Name,@typeName,@Resmoney,@Lendmoney,@Userlendmoney," +
                "@Workflowid,@Worktaskid,@Workflowinsid,@Worktaskinsid)";
                System.Guid guid = Guid.NewGuid();
                sqlDataItem1.CommandText = sql;
                sqlDataItem1.ParameterList.Clear();
                sqlDataItem1.AppendParameter("@ID", guid.ToString());
                sqlDataItem1.AppendParameter("@Code", oacost.Code);
                sqlDataItem1.AppendParameter("@Name", oacost.Name);
                sqlDataItem1.AppendParameter("@typeName", oacost.typeName);
                sqlDataItem1.AppendParameter("@Resmoney",oacost.Resmoney.ToString());
                sqlDataItem1.AppendParameter("@Lendmoney", oacost.Lendmoney);
                sqlDataItem1.AppendParameter("@Userlendmoney", oacost.Userlendmoney.ToString());
                sqlDataItem1.AppendParameter("@Workflowid", oacost.WorkflowId);
                sqlDataItem1.AppendParameter("@Worktaskid", oacost.WorktaskId);
                sqlDataItem1.AppendParameter("@Workflowinsid", oacost.WorkflowInsId);
                sqlDataItem1.AppendParameter("@Worktaskinsid", oacost.WorktaskInsId);

                SqlDataItemArray sqlItemAry = new SqlDataItemArray();
                sqlItemAry.AppendSqlItem(sqlDataItem);
                sqlItemAry.AppendSqlItem(sqlDataItem1);

                ClientDBAgent agent = new ClientDBAgent();
                agent.ExecuteNonQueryArray(sqlItemAry);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

    }
}
